﻿USE [ESRP]
GO

IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_DocumentePlata_Parteneri]') AND parent_object_id = OBJECT_ID(N'[dbo].[DocumentePlata]'))
ALTER TABLE [dbo].[DocumentePlata] DROP CONSTRAINT [FK_DocumentePlata_Parteneri]
GO

IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_DocumentePlata_TipDocumentPlata]') AND parent_object_id = OBJECT_ID(N'[dbo].[DocumentePlata]'))
ALTER TABLE [dbo].[DocumentePlata] DROP CONSTRAINT [FK_DocumentePlata_TipDocumentPlata]
GO

IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[DF_DocumentePlata_Valoare]') AND type = 'D')
BEGIN
ALTER TABLE [dbo].[DocumentePlata] DROP CONSTRAINT [DF_DocumentePlata_Valoare]
END

GO

IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[DF_DocumentePlata_TipOperatiune]') AND type = 'D')
BEGIN
ALTER TABLE [dbo].[DocumentePlata] DROP CONSTRAINT [DF_DocumentePlata_TipOperatiune]
END

GO

USE [ESRP]
GO

/****** Object:  Table [dbo].[DocumentePlata]    Script Date: 07/25/2010 22:13:09 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[DocumentePlata]') AND type in (N'U'))
DROP TABLE [dbo].[DocumentePlata]
GO

USE [ESRP]
GO

/****** Object:  Table [dbo].[DocumentePlata]    Script Date: 07/25/2010 22:13:09 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

SET ANSI_PADDING ON
GO

CREATE TABLE [dbo].[DocumentePlata](
	[IDDocumentPlata] [int] IDENTITY(1,1) NOT NULL,
	[Numar] [varchar](20) NOT NULL,
	[Data] [datetime] NOT NULL,
	[IDTipPlata] [smallint] NOT NULL,
	[ValoareTotala] [decimal](18, 2) NOT NULL,
	[IDPartener] [bigint] NOT NULL,
	[Reprezentand] [varchar](250) NULL,
	[TipOperatiune] [varchar](10) NOT NULL,
 CONSTRAINT [PK_DocumentePlata] PRIMARY KEY CLUSTERED 
(
	[IDDocumentPlata] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

SET ANSI_PADDING OFF
GO

ALTER TABLE [dbo].[DocumentePlata]  WITH CHECK ADD  CONSTRAINT [FK_DocumentePlata_Parteneri] FOREIGN KEY([IDPartener])
REFERENCES [dbo].[Parteneri] ([IDPartener])
GO

ALTER TABLE [dbo].[DocumentePlata] CHECK CONSTRAINT [FK_DocumentePlata_Parteneri]
GO

ALTER TABLE [dbo].[DocumentePlata]  WITH CHECK ADD  CONSTRAINT [FK_DocumentePlata_TipDocumentPlata] FOREIGN KEY([IDTipPlata])
REFERENCES [dbo].[TipDocumentPlata] ([IDTipPlata])
GO

ALTER TABLE [dbo].[DocumentePlata] CHECK CONSTRAINT [FK_DocumentePlata_TipDocumentPlata]
GO

ALTER TABLE [dbo].[DocumentePlata] ADD  CONSTRAINT [DF_DocumentePlata_Valoare]  DEFAULT ((0)) FOR [ValoareTotala]
GO

ALTER TABLE [dbo].[DocumentePlata] ADD  CONSTRAINT [DF_DocumentePlata_TipOperatiune]  DEFAULT ('INC') FOR [TipOperatiune]
GO

USE [ESRP]
GO

IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_DocumentePlataDetaliu_DocumentePlata]') AND parent_object_id = OBJECT_ID(N'[dbo].[DocumentePlataDetaliu]'))
ALTER TABLE [dbo].[DocumentePlataDetaliu] DROP CONSTRAINT [FK_DocumentePlataDetaliu_DocumentePlata]
GO

IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_DocumentePlataDetaliu_DocumentePlataDetaliu]') AND parent_object_id = OBJECT_ID(N'[dbo].[DocumentePlataDetaliu]'))
ALTER TABLE [dbo].[DocumentePlataDetaliu] DROP CONSTRAINT [FK_DocumentePlataDetaliu_DocumentePlataDetaliu]
GO

IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[DF_DocumentePlataDetaliu_Valoare]') AND type = 'D')
BEGIN
ALTER TABLE [dbo].[DocumentePlataDetaliu] DROP CONSTRAINT [DF_DocumentePlataDetaliu_Valoare]
END

GO


/****** Object:  Table [dbo].[DocumentePlataDetaliu]    Script Date: 07/25/2010 22:13:30 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[DocumentePlataDetaliu]') AND type in (N'U'))
DROP TABLE [dbo].[DocumentePlataDetaliu]
GO

USE [ESRP]
GO

/****** Object:  Table [dbo].[DocumentePlataDetaliu]    Script Date: 07/25/2010 22:13:30 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[DocumentePlataDetaliu](
	[IDDocPlataDetaliu] [int] IDENTITY(1,1) NOT NULL,
	[IDDocument] [bigint] NULL,
	[IDDocumentPlata] [int] NOT NULL,
	[Valoare] [decimal](18, 2) NOT NULL,
 CONSTRAINT [PK_DocumentePlataDetaliu] PRIMARY KEY CLUSTERED 
(
	[IDDocPlataDetaliu] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

ALTER TABLE [dbo].[DocumentePlataDetaliu]  WITH CHECK ADD  CONSTRAINT [FK_DocumentePlataDetaliu_DocumentePlata] FOREIGN KEY([IDDocumentPlata])
REFERENCES [dbo].[DocumentePlata] ([IDDocumentPlata])
GO

ALTER TABLE [dbo].[DocumentePlataDetaliu] CHECK CONSTRAINT [FK_DocumentePlataDetaliu_DocumentePlata]
GO

ALTER TABLE [dbo].[DocumentePlataDetaliu]  WITH CHECK ADD  CONSTRAINT [FK_DocumentePlataDetaliu_DocumentePlataDetaliu] FOREIGN KEY([IDDocument])
REFERENCES [dbo].[Documente] ([IDDocument])
GO

ALTER TABLE [dbo].[DocumentePlataDetaliu] CHECK CONSTRAINT [FK_DocumentePlataDetaliu_DocumentePlataDetaliu]
GO

ALTER TABLE [dbo].[DocumentePlataDetaliu] ADD  CONSTRAINT [DF_DocumentePlataDetaliu_Valoare]  DEFAULT ((0)) FOR [Valoare]
GO


